<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="问题列表"></uni-navbar></view>

		<view class="filter-box">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="问题标题">
						<!-- block -->
						<u-input v-model="masses.title" type="text" placeholder="请输入问题标题" />
					</u-form-item>
					<u-form-item class="form-item" label="提交人">
						<!-- block -->
						<u-input v-model="masses.userName" type="text" placeholder="请输入提交人" />
					</u-form-item>
					<u-form-item class="form-item" label="常委">
						<!-- block -->
						<u-input v-model="masses.cwName" type="text" placeholder="请输入常委姓名" />
					</u-form-item>
				</u-form>
			</view>
			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" shape="circle" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" shape="circle" @click="filter">确定</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import dateTimePicker from '@/components/uni-datetime-picker';
import { mapState } from 'vuex';
export default {
	components: {
		dateTimePicker
	},
	data() {
		return {
			title: '',

			type: '',
			typeShow: false,
			typeList: [],

			createTime: '',
			endTime: '',

			massesList: [],

			startTime: '',
			endTime: '',

			masses: {
				title: '',
				numCode: '',
				cwName: '',
				dateRangeSea: '',
				userName: '',
				nodeStatus: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();
		if (option && option.data) {
			this.masses = JSON.parse(option.data);
		}

		const eventChannel = this.getOpenerEventChannel();
		eventChannel.on('masses', (data) => {
			Object.assign(this.masses, data);
		});
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	computed: {
		dateRangeSea: {
			get: function() {
				let time = this.startTime + ' - ' + this.endTime;
				if (this.startTime == '' || this.endTime == '') {
					return '';
				} else {
					return time;
				}
			},
			set: function(e) {
				this.startTime = '';
				this.endTime = '';
			}
		},
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.roleCodes = this.userInfo.roleCodes.join(',');
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			// let pre = this.$prePage();
			// if (pre && pre.loadData) {
			// 	pre.masses = this.masses;
			// 	pre.loadData('refresh');
			// }
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.emit('loadData', this.masses);
			uni.navigateBack();
		},
		typeConfirm(e) {
			this.type = e[0].label;
			this.masses.processType = e[0].value;
		},
		timeChange({ date, dt }, idx) {
			this[idx] = date.year + '-' + date.month2 + '-' + date.day2;
		},
		filter() {
			if (this.startTime == '' && this.endTime != '') {
				this.$msg('请选择开始时间');
				return false;
			}
			if (this.startTime != '' && this.endTime == '') {
				this.$msg('请选择结束时间');
				return false;
			}
			let arr = this.startTime.split('-');
			let startTime = new Date(arr[0], arr[1], arr[2]).getTime();

			let arrs = this.endTime.split('-');
			let endTime = new Date(arrs[0], arrs[1], arrs[2]).getTime();

			if (startTime >= endTime) {
				this.$msg('开始时间应小于结束时间');
				return false;
			}

			this.masses.dateRangeSea = this.dateRangeSea;

			this.loadData('refresh');
		},
		resert() {
			this.masses.title = '';
			this.masses.numCode = '';
			this.masses.cwName = '';
			this.masses.dateRangeSea = '';
			this.masses.userName = '';
			this.loadData('refresh');
		},
		search(e) {
			this.masses.title = e;
			this.loadData('refresh');
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

<style lang="scss">
.list-view {
	min-height: 100vh;
	background-color: #fff;
}

// .filter-box {
// 	position: fixed;
// 	left: 0;
// 	top: 0;
// 	bottom: 0;
// 	right: 0;
// 	z-index: 998;
// 	background-color: #fff;
// }

.form-box {
	.form-item {
		@include mp-flex;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
